#include "Exit.h"

#include "../ConsoleColor.h"
#include <iostream>
#include <algorithm>

Exit::Exit(ExitId id, const RoomPtr &to, const std::string &description, bool locked) 
	: GameObject("",description), id(id), to(to), locked(locked)
{
	name = getExitIdName(id);
	name_alias = getExitIdNameAlias(id);
}

Exit::~Exit()
{
}

void Exit::look() 
{ 
	std::cout << description << std::endl;
}

void Exit::add(const GameObjectPtr &object)
{
	objects.push_back(object);
}

void Exit::remove(const GameObjectPtr &object)
{
	for(unsigned int i = 0; i < objects.size(); i++)
	{
		if(object->getName() == objects[i]->getName())
		{
			objects[i] = objects.back();
			objects.pop_back();
			break;
		}
	}
}

void Exit::add(Setting setting)
{
	settings.push_back(setting);
}

bool Exit::has(Setting setting)
{
	for(unsigned int i = 0; i < settings.size(); i++)
	{
		if(settings[i] == setting)
			return true;
	}
	return false;
}

std::string Exit::getExitIdName(ExitId direction)
{
	switch(direction)
	{
	case WEST:  return "west"; break;
	case NORTH: return "north"; break;
	case EAST:  return "east"; break;
	case SOUTH: return "south"; break;
	case UP:	return "up"; break;
	case DOWN:	return "down"; break;
	case NULL_EXIT: return "nowhere"; break;
	default: return "nowhere"; break;
	};
}

std::string Exit::getExitIdNameAlias(ExitId direction)
{
	switch(direction)
	{
	case WEST:  return "w"; break;
	case NORTH: return "n"; break;
	case EAST:  return "e"; break;
	case SOUTH: return "s"; break;
	case UP:	return "u"; break;
	case DOWN:	return "d"; break;
	case NULL_EXIT: return "nowhere"; break;
	default: return "nowhere"; break;
	};
}

Exit::ExitId Exit::getOpposite(ExitId direction)
{
	switch(direction)
	{
	case WEST:  return EAST; break;
	case NORTH: return SOUTH; break;
	case EAST:  return WEST; break;
	case SOUTH: return NORTH; break;
	case UP:	return DOWN; break;
	case DOWN:	return UP; break;
	case NULL_EXIT: return NULL_EXIT; break;
	default: return NULL_EXIT; break;
	};
}
